# -*- coding: utf-8 -*-
import ix
from liberHook.BaseHook import BaseHook
from liberLibs.dccLibs import Clarisse


class Hook(BaseHook):
    def __init__(self, library, directory, ext, start, end):
        BaseHook.__init__(self, library, directory, ext, start, end)

    def execute(self):
        if not self.files:
            self.append_error("No hdr files found.")
            return
        selected = ix.selection
        if selected and selected.get_count() == 1:
            try:
                if selected[0].get_class().get_name() == "TextureMapFile":
                    selected[0].attrs.filename = str(self.files[0])
                else:
                    Clarisse.create_ibl(str(self.files[0]))
            except:
                Clarisse.create_ibl(str(self.files[0]))
        else:
            Clarisse.create_ibl(str(self.files[0]))
